package com.weixin.paleituo.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;

/**
 * Author yichao
 * Time  2017/12/11 15:44
 * Dest  新的我的item控件
 */
public class ItemNewMyView extends LinearLayout {

    private LinearLayout mLinearLayout;
    private TextView mTvName, mTvDetai;
    private View mViewLine;

    public ItemNewMyView(Context context) {
        this(context, null);
    }

    public ItemNewMyView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        mLinearLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.item_new_myfragme_layout, this, true);
        mTvName = mLinearLayout.findViewById(R.id.tv_name_item_myfragment_layout);
        mTvDetai = mLinearLayout.findViewById(R.id.tv_detail_item_myfragment_layout);
        mViewLine = mLinearLayout.findViewById(R.id.view_line_item_myfragment_layout);
         ImageView imageView= mLinearLayout.findViewById(R.id.iv_icon_item_new_myfragme_layout);
        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.CustomItemMy);
        int integer = attributes.getResourceId(R.styleable.CustomItemMy_icon, 0);
        if (integer!=0){
            imageView.setImageResource(integer);
        }
        String name = attributes.getString(R.styleable.CustomItemMy_name);
        if (name != null && !name.equals("")) {
            mTvName.setText(name);
        }
        String detais = attributes.getString(R.styleable.CustomItemMy_details);
        if (detais != null && !detais.equals("")) {
            mTvDetai.setText(detais);
        }

        boolean isShowLine=attributes.getBoolean(R.styleable.CustomItemMy_is_show_line,true);
        if (!isShowLine){
            mViewLine.setVisibility(INVISIBLE);
        }
        attributes.recycle();


    }

    public ItemNewMyView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    public void setDetails(String details){
        mTvDetai.setText(details);
    }

    public String getDetails(){

        return mTvDetai.getText().toString().trim();

    }

}
